<?php

class bgMLTestFunctional extends sfTestFunctional
{

  public function loadData()
  {
    $loader = new sfPropelData();
    $loader->loadData();
    return $this;
  }

  public function signin($user_data)
  {
    return $this->
      info("Begin login procedure")->
      info(sprintf('Connection with login : "%s" and password "%s" should be ok.', $user_data['username'], $user_data['password']))->
      get('/login')->
      with('request')->begin()->
        isParameter('module', 'sfGuardAuth')->
        isParameter('action', 'signin')->
      end()->
      with('response')->begin()->
        isStatusCode(401)->
        checkElement('input#signin_username')->
        checkElement('input#signin_password')->
      end()->
      click('sign in', array('signin' => array(
        'username' => $user_data['username'],
        'password'  => $user_data['password']
      )))
      ->with('request')->begin()
        ->isParameter('module', 'sfGuardAuth')
        ->isParameter('action', 'signin')
      ->end()
      ->with('response')->begin()
        ->isStatusCode(302)
      ->end()
      ->followRedirect()
      ->with('request')->begin()->
      end()
      ->with('response')->begin()
        ->isStatusCode(200)
      ->end()
      ->with('user')->begin()
            ->isAuthenticated()
      ->info("End login procedure")
      ->end()
       ;

  }

  public function isSecure($address)
  {
    return $this->
      info("Access without login")->
      get($address)->
      with('response')->begin()->
        isStatusCode(401)->
        checkElement('form input[id="signin_username"]', true)->
        checkElement('form input[id="signin_password"]', true)->
        checkElement('form input[type="submit"]', true)->
      end()
      ;

  }

}

?>